import * as Blockly from 'blockly/core';
import { Profile } from 'mixly';

const SENSOR_HUE = 40;

export const chaoshengbo2 = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MIXLY_CHAOSHENGBO);
        this.appendDummyInput("")
            .appendField('Trig#')
            .appendField(new Blockly.FieldDropdown(Profile.default.digital), "Trig")
            .appendField('Echo#')
            .appendField(new Blockly.FieldDropdown(Profile.default.digital), "Echo");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_BLOCKGROUP_CHAOSHENGBO);
        // this.setFieldValue("2","Trig");
        // this.setFieldValue("4","Echo");
    }
};

//DS18B20温度传感器
export const ds18b20 = {
    init: function () {
        var UNIT = [[Blockly.Msg.MIXLY_DS18B20_C, '0'], [Blockly.Msg.MIXLY_DS18B20_F, '1']];
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MIXLY_DS18B20)
            .appendField(new Blockly.FieldDropdown(Profile.default.digital), "PIN")
            .appendField(Blockly.Msg.MIXLY_GETTEMPERATUE)
            .appendField(new Blockly.FieldDropdown(UNIT), "UNIT");
        this.setOutput(true, Number);
        this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_DS18);
    }
};

const BMX280_VALUE_TYPE = {
    bme: [
        [Blockly.Msg.blynk_IOT_IR_TEMP, "readTemperature()"],
        [Blockly.Msg.MIXLY_Humidity, "readHumidity()"],
        [Blockly.Msg.MIXLY_Altitude, "readPressure()"],
        [Blockly.Msg.MIXLY_HEIGHT, "readAltitude(SEALEVELPRESSURE_HPA)"]
    ],
    bmp: [
        [Blockly.Msg.blynk_IOT_IR_TEMP, "readTemperature()"],
        [Blockly.Msg.MIXLY_Altitude, "readPressure()"],
        [Blockly.Msg.MIXLY_HEIGHT, "readAltitude(SEALEVELPRESSURE_HPA)"]
    ]
};

//BMX280
export const bmx280_read_data = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput()
            .appendField(Blockly.Msg.MIXLY_SERIAL_READ)
            .appendField(new Blockly.FieldDropdown([["BME280", "bme"], ["BMP280", "bmp"]]), 'TYPE');
        this.appendValueInput("address")
            .appendField(Blockly.Msg.MIXLY_LCD_ADDRESS);
        this.appendDummyInput()
            .appendField(Blockly.Msg.MIXLY_GET)
            .appendField(new Blockly.FieldDependentDropdown("TYPE", BMX280_VALUE_TYPE, BMX280_VALUE_TYPE['bme']), 'BME_TYPE');
        this.appendDummyInput()
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField(' ' + Blockly.Msg.CONTROLS_FOR_INPUT_WITH)
            .appendField(new Blockly.FieldDropdown([
                ["I2C1", "Wire1"],
                ["I2C1(" + Blockly.Msg.MIXLY_STM32_SPI_REMAP + ")", "remap_I2C_1"],
                ["I2C2", "Wire2"]
            ]), "I2C_TYPE");
        this.setOutput(true, null);
        this.setInputsInline(true);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

// SHT20传感器
export const sht20_get_data = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField("SHT20" + Blockly.Msg.MIXLY_DHT11_T_H);
        this.appendDummyInput("")
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MIXLY_TEMPERATURE, "readTemperature()"],
                [Blockly.Msg.MIXLY_Humidity, "readHumidity()"],
            ]), "SHT20_TYPE");
        this.appendDummyInput()
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField(' ' + Blockly.Msg.CONTROLS_FOR_INPUT_WITH)
            .appendField(new Blockly.FieldDropdown([
                ["I2C1", "Wire1"],
                ["I2C1(" + Blockly.Msg.MIXLY_STM32_SPI_REMAP + ")", "remap_I2C_1"],
                ["I2C2", "Wire2"]
            ]), "I2C_TYPE");
        this.setInputsInline(true);
        this.setOutput(true);
        this.setTooltip();
    }
};

// 初始化TCS230颜色传感器
export const tcs230_init = {
    init: function () {
        this.appendDummyInput()
            .appendField(Blockly.Msg.MIXLY_SETUP + " TCS230");
        this.appendValueInput("tcs230_s0")
            .setCheck(null)
            .appendField("S0");
        this.appendValueInput("tcs230_s1")
            .setCheck(null)
            .appendField("S1");
        this.appendValueInput("tcs230_s2")
            .setCheck(null)
            .appendField("S2");
        this.appendValueInput("tcs230_s3")
            .setCheck(null)
            .appendField("S3");
        this.appendValueInput("tcs230_led")
            .setCheck(null)
            .appendField("LED");
        this.appendValueInput("tcs230_out")
            .setCheck(null)
            .appendField("OUT");
        this.setInputsInline(true);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(SENSOR_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

// TCS230颜色传感器 获取RGB值
export const tcs230_Get_RGB = {
    init: function () {
        this.appendDummyInput()
            .appendField("TCS230")
            .appendField(Blockly.Msg.MIXLY_GET)
            .appendField(new Blockly.FieldDropdown([[Blockly.Msg.COLOUR_RGB_RED, "R"], [Blockly.Msg.COLOUR_RGB_GREEN, "G"], [Blockly.Msg.COLOUR_RGB_BLUE, "B"]]), "tcs230_color");
        this.setInputsInline(true);
        this.setOutput(true, null);
        this.setColour(SENSOR_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

// MPU6050更新数据
export const mpu6050_update = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MIXLY_MPU6050 + Blockly.Msg.MIXLY_update_data);
        this.appendDummyInput()
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField(' ' + Blockly.Msg.CONTROLS_FOR_INPUT_WITH)
            .appendField(new Blockly.FieldDropdown([
                ["I2C1", "Wire1"],
                ["I2C1(" + Blockly.Msg.MIXLY_STM32_SPI_REMAP + ")", "remap_I2C_1"],
                ["I2C2", "Wire2"]
            ]), "I2C_TYPE");
        this.setPreviousStatement(true);
        this.setNextStatement(true);
        this.setInputsInline(true);
    }
};

// MPU6050获取数据
export const mpu6050_get_data = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MIXLY_MPU6050);
        this.appendDummyInput("")
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MIXLY_Accel_X, "getAccX()"],
                [Blockly.Msg.MIXLY_Accel_Y, "getAccY()"],
                [Blockly.Msg.MIXLY_Accel_Z, "getAccZ()"],
                [Blockly.Msg.MIXLY_Gyro_X, "getAngleX()"],
                [Blockly.Msg.MIXLY_Gyro_Y, "getAngleY()"],
                [Blockly.Msg.MIXLY_Gyro_Z, "getAngleZ()"],
                [Blockly.Msg.MIXLY_readTempC, "getTemp()"]
            ]), "MPU6050_TYPE");
        this.appendDummyInput()
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField(' ' + Blockly.Msg.CONTROLS_FOR_INPUT_WITH)
            .appendField(new Blockly.FieldDropdown([
                ["I2C1", "Wire1"],
                ["I2C1(" + Blockly.Msg.MIXLY_STM32_SPI_REMAP + ")", "remap_I2C_1"],
                ["I2C2", "Wire2"]
            ]), "I2C_TYPE");
        this.setInputsInline(true);
        this.setOutput(true);
    }
};

//DF称重模块
export const weightSensor = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField("Hx711")
            .appendField(Blockly.Msg.MIXLY_WEIGHTSENSOR);
        this.appendDummyInput("")
            .appendField('Dout#')
            .appendField(new Blockly.FieldDropdown(Profile.default.digital), "DOUT")
            .appendField('SCK#')
            .appendField(new Blockly.FieldDropdown(Profile.default.digital), "SCK");
        this.appendValueInput("scale")
            .setCheck(Number)
            .appendField(Blockly.Msg.HX711_scale);
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_BLOCKGROUP_WEIGHTSENSOR);
        // this.setFieldValue("2","DOUT");
        // this.setFieldValue("4","SCK");
    }
};

var Encoder_NO = [
    [Blockly.Msg.MIXLY_ENCODER + 1, "1"],
    [Blockly.Msg.MIXLY_ENCODER + 2, "2"],
    [Blockly.Msg.MIXLY_ENCODER + 3, "3"],
    [Blockly.Msg.MIXLY_ENCODER + 4, "4"]
];

// 旋转编码器定义
export const sensor_encoder_init = {
    init: function () {
        this.appendDummyInput()
            .appendField(Blockly.Msg.MIXLY_SETUP)
            .appendField(new Blockly.FieldDropdown(Encoder_NO), "TYPE");
        this.appendValueInput("CLK")
            .setCheck(null)
            .appendField("CLK#");
        this.appendValueInput("DT")
            .setCheck(null)
            .appendField("DT#");
        this.setInputsInline(true);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(SENSOR_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

// 旋转编码器读取
export const sensor_encoder_get = {
    init: function () {
        this.appendDummyInput()
            .appendField(new Blockly.FieldDropdown(Encoder_NO), "TYPE")
            .appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_GET)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MIXLY_GPS_LOCATION, "getPosition"],
                [Blockly.Msg.MIXLY_MICROBIT_Direction, "getDirection"],
                [Blockly.Msg.MIXLY_INCREMENT, "getIncrement"],
                [Blockly.Msg.MIXLY_UPPERBOUND, "getUpperBound"],
                [Blockly.Msg.MIXLY_LOWERBOUND, "getLowerBound"]
            ]), "OPERATE_TYPE");
        this.setInputsInline(true);
        this.setOutput(true, null);
        this.setColour(SENSOR_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

// 旋转编码器设置
export const sensor_encoder_set = {
    init: function () {
        this.appendDummyInput()
            .appendField(new Blockly.FieldDropdown(Encoder_NO), "TYPE");
        this.appendValueInput("DATA")
            .setCheck(null)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MIXLY_GPS_LOCATION, "resetPosition"],
                [Blockly.Msg.MIXLY_INCREMENT, "setIncrement"],
                [Blockly.Msg.MIXLY_UPPERBOUND, "setUpperBound"],
                [Blockly.Msg.MIXLY_LOWERBOUND, "setLowerBound"]
            ]), "OPERATE_TYPE")
            .appendField(Blockly.Msg.MIXLY_STAT);
        this.setInputsInline(true);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(SENSOR_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

// 旋转编码器事件
export const sensor_encoder_handle = {
    init: function () {
        this.appendDummyInput()
            .appendField(new Blockly.FieldDropdown(Encoder_NO), "TYPE")
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MIXLY_ENCODER_CHANGED, "setChangedHandler"],
                [Blockly.Msg.MIXLY_ENCODER_LEFT_ROTATION, "setLeftRotationHandler"],
                [Blockly.Msg.MIXLY_ENCODER_RIGHT_ROTATION, "setRightRotationHandler"],
                [Blockly.Msg.MIXLY_ENCODER_UPPER_OVERFLOW, "setUpperOverflowHandler"],
                [Blockly.Msg.MIXLY_ENCODER_LOWER_OVERFLOW, "setLowerOverflowHandler"]
            ]), "OPERATE_TYPE");
        this.appendStatementInput("DO")
            .setCheck(null)
            .appendField(Blockly.Msg.MIXLY_MSTIMER2_DO);
        this.setInputsInline(true);
        this.setColour(SENSOR_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

//DS1302 RTC
export const DS1302_init = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField(Blockly.Msg.MIXLY_DS1302_INITPIN);
        //.appendField(new Blockly.FieldTextInput('myRTC'), 'RTCName');
        this.appendValueInput("RST", Number)
            .appendField("RST#")
            .setCheck(Number);
        this.appendValueInput("DAT")
            .appendField("DAT#")
            .setCheck(Number);
        this.appendValueInput("CLK")
            .appendField("CLK#")
            .setCheck(Number);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setInputsInline(true);
        this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_DS1302_INIT);
    }
}

var RTCTypeList = [['DS1307', 'RtcDS1307'], ['DS3231', 'RtcDS3231']];

//DS1307 RTC
export const DS1307_init = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MIXLY_RTCINIT);
        this.appendDummyInput("").setAlign(Blockly.ALIGN_RIGHT).appendField(new Blockly.FieldDropdown(RTCTypeList), 'RTCType');
        this.appendDummyInput("")
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField(Blockly.Msg.MIXLY_PIN);
        this.appendDummyInput()
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField(Blockly.Msg.CONTROLS_FOR_INPUT_WITH)
            .appendField(new Blockly.FieldDropdown([
                ["I2C1", "Wire1"],
                ["I2C1(" + Blockly.Msg.MIXLY_STM32_SPI_REMAP + ")", "remap_I2C_1"],
                ["I2C2", "Wire2"]
            ]), "I2C_TYPE");
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setInputsInline(true);
        this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_DS1307_INIT);
    }
};
//传感器-实时时钟块_时间变量
var RTC_TIME_TYPE = [
    [Blockly.Msg.MIXLY_YEAR, "Year"],
    [Blockly.Msg.MIXLY_MONTH, "Month"],
    [Blockly.Msg.MIXLY_DAY, "Day"],
    [Blockly.Msg.MIXLY_HOUR, "Hour"],
    [Blockly.Msg.MIXLY_MINUTE, "Minute"],
    [Blockly.Msg.MIXLY_SECOND, "Second"],
    [Blockly.Msg.MIXLY_WEEK, "DayOfWeek"],

];

//传感器-实时时钟块_获取时间
export const RTC_get_time = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField("RTC" + Blockly.Msg.MIXLY_RTCGETTIME);
        this.appendDummyInput("")
            .setAlign(Blockly.ALIGN_RIGHT);
        //.appendField(new Blockly.FieldTextInput('myRTC'), 'RTCName');
        this.appendDummyInput("")
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField(new Blockly.FieldDropdown(RTC_TIME_TYPE), "TIME_TYPE");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_RTC_GETTIME.replace('%1', this.getFieldValue("TIME_TYPE")));
    }
};
// 传感器-实时时钟块_设置时间
export const RTC_time = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendValueInput("hour")
            .setCheck(Number);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MIXLY_HOUR);
        this.appendValueInput("minute")
            .setCheck(Number);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MIXLY_MINUTE);
        this.appendValueInput("second")
            .setCheck(Number);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MIXLY_SECOND);
        this.setInputsInline(true);
        this.setOutput(true, null);
        this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_RTC_SETTIME);
    }
};

export const RTC_date = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendValueInput("year")
            .setCheck(Number);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MIXLY_YEAR);
        this.appendValueInput("month")
            .setCheck(Number);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MIXLY_MONTH);
        this.appendValueInput("day")
            .setCheck(Number);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MIXLY_DAY);
        this.setInputsInline(true);
        this.setOutput(true, null);
        this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_RTC_SETTIME);
    }
};

// 设置时间
export const RTC_set_time = {
    init: function () {
        this.appendDummyInput()
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField("RTC" + Blockly.Msg.MIXLY_RTCSETTIME);
        this.appendValueInput("date")
            .appendField(Blockly.Msg.MIXLY_GPS_DATE);
        this.appendValueInput("time")
            .appendField(Blockly.Msg.MIXLY_GPS_TIME);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(SENSOR_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

// 获取烧录时间和日期
export const get_system_date_time = {
    init: function () {
        this.appendDummyInput()
            .appendField(Blockly.Msg.MIXLY_GET + " " + Blockly.Msg.MIXLY_SYSTEM)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MIXLY_GPS_DATE, "DATE"],
                [Blockly.Msg.MIXLY_GPS_TIME, "TIME"]
            ]), "type");
        this.setInputsInline(false);
        this.setOutput(true, null);
        this.setColour(40);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

export const gps_init = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput()
            .appendField(Blockly.Msg.MIXLY_GPS_INIT)
        this.appendValueInput("RX")
            .appendField("RX#")
            .setCheck(null);
        this.appendValueInput("TX")
            .appendField("TX#")
            .setCheck(null);
        this.appendValueInput("CONTENT", Number)
            .appendField(Blockly.Msg.MIXLY_SERIAL_BEGIN)
            .setCheck(Number);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setInputsInline(true);
        this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_GPS_INIT);
    }
};

export const gps_data_available = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput()
            .appendField(Blockly.Msg.MIXLY_GPS_DATA_AVAILABLE);
        this.setOutput(true, Boolean);
        this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_GPS_DATA_AVAILABLE);
    }
};

export const gps_data_encode = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput()
            .appendField(Blockly.Msg.MIXLY_GPS_DATA_ENCODE);
        this.setOutput(true, Boolean);
    }
};

export const gps_xxx_isValid = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput()
            .appendField("GPS")
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MIXLY_GPS_LOCATION, "location"],
                [Blockly.Msg.MIXLY_GPS_DATE, "date"],
                [Blockly.Msg.MIXLY_GPS_TIME, "time"]
            ]), "WHAT")
            .appendField(Blockly.Msg.MIXLY_GPS_ISVALID);
        this.setOutput(true, Boolean);
        this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_GPS_DATA_VAILD);
    }
};

export const gps_getData_xxx = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput()
            .appendField(Blockly.Msg.MIXLY_GPS_GET)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MIXLY_GPS_LOCATION_LAT, "location.lat"],
                [Blockly.Msg.MIXLY_GPS_LOCATION_LNG, "location.lng"],
                [Blockly.Msg.MIXLY_GPS_DATE_YEAR, "date.year"],
                [Blockly.Msg.MIXLY_GPS_DATE_MONTH, "date.month"],
                [Blockly.Msg.MIXLY_GPS_DATE_DAY, "date.day"],
                [Blockly.Msg.MIXLY_GPS_TIME_HOUR, "time.hour"],
                [Blockly.Msg.MIXLY_GPS_TIME_MINUTE, "time.minute"],
                [Blockly.Msg.MIXLY_GPS_TIME_SECOND, "time.second"],
                [Blockly.Msg.MIXLY_GPS_TIME_CENTISECOND, "time.centisecond"]
            ]), "WHAT");
        this.setOutput(true, Number);
        this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_GPS_GETDATA.replace('%1', this.getFieldValue('WHAT')));
    }
};

//PS2
export const PS2_init = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MIXLY_SETUP + Blockly.Msg.PS2);
        this.appendDummyInput("")
            .appendField('DAT#')
            .appendField(new Blockly.FieldDropdown(Profile.default.digital), "PS2_DAT")
            .appendField('CMD#')
            .appendField(new Blockly.FieldDropdown(Profile.default.digital), "PS2_CMD")
            .appendField('SEL#')
            .appendField(new Blockly.FieldDropdown(Profile.default.digital), "PS2_SEL")
            .appendField('CLK#')
            .appendField(new Blockly.FieldDropdown(Profile.default.digital), "PS2_CLK");
        this.appendDummyInput("")
            .appendField(Blockly.Msg.PS2_setRumble)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MIXLY_ON, "true"],
                [Blockly.Msg.MIXLY_OFF, "false"]
            ]), "rumble");
        this.setInputsInline(true);
        this.setPreviousStatement(true);
        this.setNextStatement(true);
        this.setTooltip('');
    }
};
export const PS2_update = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.PS2 + Blockly.Msg.MIXLY_update_data);
        this.setPreviousStatement(true);
        this.setNextStatement(true);
        this.setInputsInline(true);
    }
};
var PSBUTTON = [
    [Blockly.Msg.PS2_TRIANGLE, "PSB_GREEN"],
    [Blockly.Msg.PS2_CIRCLE, "PSB_RED"],
    [Blockly.Msg.PS2_CROSS, "PSB_BLUE"],
    [Blockly.Msg.PS2_SQUARE, "PSB_PINK"],
    [Blockly.Msg.PS2_L1, "PSB_L1"],
    [Blockly.Msg.PS2_L2, "PSB_L2"],
    // ["PSB_L3","PSB_L3"],
    [Blockly.Msg.PS2_R1, "PSB_R1"],
    [Blockly.Msg.PS2_R2, "PSB_R2"],
    // ["PSB_R3","PSB_R3"],
    [Blockly.Msg.PS2_UP, "PSB_PAD_UP"],
    [Blockly.Msg.PS2_RIGHT, "PSB_PAD_RIGHT"],
    [Blockly.Msg.PS2_DOWN, "PSB_PAD_DOWN"],
    [Blockly.Msg.PS2_LEFT, "PSB_PAD_LEFT"],
    [Blockly.Msg.PS2_SELECT, "PSB_SELECT"],
    [Blockly.Msg.PS2_START, "PSB_START"]
];

//
export const PS2_Button = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField(Blockly.Msg.PS2_BUTTON)
            .appendField(new Blockly.FieldDropdown(PSBUTTON), "psbt")
            .appendField(Blockly.Msg.MIXLY_PULSEIN_STAT)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MIXLY_BUTTON_HOLD, "Button"],
                [Blockly.Msg.MIXLY_BUTTON_PRESSED, "ButtonPressed"],
                [Blockly.Msg.MIXLY_BUTTON_RELEASED, "ButtonReleased"],
                [Blockly.Msg.MIXLY_CHANGE, "NewButtonState"]
            ]), "btstate");
        this.setOutput(true, Boolean);
        this.setTooltip('');
    }
};

export const PS2_stk = {
    init: function () {
        this.setColour(SENSOR_HUE);
        var PSSTK = [
            [Blockly.Msg.PS2_RX, "PSS_RX"],
            [Blockly.Msg.PS2_RY, "PSS_RY"],
            [Blockly.Msg.PS2_LX, "PSS_LX"],
            [Blockly.Msg.PS2_LY, "PSS_LY"],
        ];
        this.appendDummyInput("")
            .appendField(Blockly.Msg.PS2_stick)
            .appendField(new Blockly.FieldDropdown(PSSTK), "psstk");
        this.setOutput(true, Number);
        this.setTooltip('');
    }
};